package com.gtt.lazy.service.impl;

import java.util.List;

import com.gtt.lazy.domain.Colors;
import com.gtt.lazy.service.ColorService;
import com.gtt.lazy.util.HibernateTemplateUtil;

public class ColorServiceImpl implements ColorService {

	private HibernateTemplateUtil hibernateTemplateUtil;

	public int add(Colors color) {
		return (Integer) hibernateTemplateUtil.save(color);
	}

	public void delete(int id) {
		hibernateTemplateUtil.delete(Colors.class, id);
	}

	public Colors get(int id) {
		return (Colors) hibernateTemplateUtil.get(Colors.class, id);
	}

	@SuppressWarnings("unchecked")
	public List<Colors> list() {
		String hql = "from Colors c order by c.recommend desc";
		return hibernateTemplateUtil.find(hql);
	}

	@SuppressWarnings("unchecked")
	public List<Colors> list(int ccid, int start, int size) {
		String hql = "from Colors c where c.ccid=" + ccid
				+ " order by c.recommend desc";
		return hibernateTemplateUtil.find(hql, start, size);
	}

	public void update(Colors color) {
		hibernateTemplateUtil.update(color);
	}

	public void updateRecommend(int id, int recommend) {
		Colors colors = get(id);
		colors.setRecommend(recommend);
		update(colors);
	}

	public int count(int ccid) {
		String hql = "select count(*) from Colors as c where c.ccid=" + ccid;
		Long l = (Long) hibernateTemplateUtil.find(hql).get(0);
		return l.intValue();
	}

	public int count() {
		String hql = "select count(*) from Colors as c";
		Long l = (Long) hibernateTemplateUtil.find(hql).get(0);
		return l.intValue();
	}

	public HibernateTemplateUtil getHibernateTemplateUtil() {
		return hibernateTemplateUtil;
	}

	public void setHibernateTemplateUtil(
			HibernateTemplateUtil hibernateTemplateUtil) {
		this.hibernateTemplateUtil = hibernateTemplateUtil;
	}

}
